package com.spark.lola.logistics.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spark.lola.logistics.entity.DriverInfo;
import com.spark.lola.support.mybatis.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

/**
 * @author: Zhi-peng wang
 * @date: 2020/04/24 13:04
 * 驾驶员信息mapper
 **/
@Mapper
public interface DriverInfoMapper extends BaseMapper<DriverInfo> {

    /**
     * @description: 分页查询驾驶员信息
     * @author: wzp
     * @date: 2020/4/24
     */
    IPage<DriverInfo> findPage(Page<DriverInfo> page, @Param(Constants.WRAPPER) Wrapper<DriverInfo> wrapper);

    @Select("select o.*,o.is_bind,c.no carNo,c.name carName from logistics_driver_info o left join logistics_car_info c on o.car_id=c.id where o.id=#{id}")
    DriverInfo findInfo(long id);

    @Select("select o.*,o.is_bind,c.no carNo,c.name carName from logistics_driver_info o left join logistics_car_info c on o.car_id=c.id where o.emp_id=#{empId}")
    DriverInfo findByEmpId(long empId);

    @Select("select count(*) from logistics_driver_info where car_id=#{carId}")
    int countByCarId(long carId);

    @Select("select emp_id from logistics_driver_info where emp_id is not null")
    List<Long> findEmpId();

    @Select("select count(*) from logistics_driver_info where emp_id=#{empId}")
    int countByEmpId(long empId);

    @Update("update logistics_driver_info set car_id=#{carId},is_bind=#{isBind} where id=#{id}")
    int updateCarIdById(Long carId, int isBind, long id);

    @Select("select car_id from logistics_driver_info where id=#{id}")
    Long findCarIdById(long id);

    @Select("select real_name from logistics_driver_info where id=#{id}")
    String findRealNameById(long id);

    @Select("select emp_id from logistics_driver_info where car_id=#{carId}")
    long findEmpIdByCarId(long carId);

    @Select("select count(*) from logistics_driver_info where used=#{used}")
    int countByUsed(String used);

    @Select("select emp_id from logistics_driver_info where emp_id is not null and used='Y'")
    List<Long> findAllEmpId();

}
